﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Jok.Client.Loader;
using Jok.Client.Loader.PackagesService;

namespace Jok.Client.Loader
{
    public partial class LoadingView : UserControl, ILoaderView
    {
        public LoadingView()
        {
            InitializeComponent();

            ShellPresenter.Visibility = Visibility.Collapsed;
            StorageInscreeser.Visibility = App.PackagesManager.StorageMemoryRequired ? Visibility.Visible : Visibility.Collapsed;
        }

        #region ISilverlightLoader Members

        public void InitCallback()
        {
        }

        public void DownloadStartCallback(Package Package)
        {
            lblNotification.Text = String.Format("Loading {0}", Package.Name);
        }

        public void DownloadProgressCallback(Package Package, DownloadProgressEventArgs eventArgs)
        {
        }

        public void DownloadCompleteCallback(Package Package, DownloadCompleteEventArgs eventArgs)
        {
        }

        public void LoadPackage(Package Package)
        {
        }

        public void SetShell(UIElement ShellView)
        {
            this.ShellPresenter.Content = ShellView;
            this.ShellPresenter.Visibility = Visibility.Visible;

            this.LoadingGrid.Visibility = Visibility.Collapsed;
        }

        #endregion


        private void StorageInscreeser_Click(object sender, RoutedEventArgs e)
        {
            if (App.PackagesManager.StorageMemoryRequired)
                throw new Exception("Not enought memory, please run again and press Yes!");

            App.PackagesManager.StartLoading();
        }
    }
}
